package com.github.livebase.util.base;

import android.text.TextUtils;

/**
 * @ClassName NumberUtil
 * @description:
 * @author: biao532
 * @create: 2024-01-21 09:07
 * @Version 1.0
 **/
public class NumberUtil {
    public static int parseInt(String str, int radix, int d) {
        if (TextUtils.isEmpty(str)) {
            return d;
        }
        try {
            return Integer.valueOf(str, radix);
        }
        catch (NumberFormatException e) {
            return d;
        }
    }
    public static int toInteger(String str, int d) {
        return parseInt(str, 10, d);
    }

    public static float toFloat(String str, float d) {
        if (TextUtils.isEmpty(str)) {
            return d;
        }
        try {
            return Float.valueOf(str).floatValue();
        }
        catch (NumberFormatException e) {
            return d;
        }

    }
    public static long toLong(String str, long d) {
        if (TextUtils.isEmpty(str)) {
            return d;
        }
        try {
            return Long.valueOf(str).longValue();
        }
        catch (NumberFormatException e) {
            return d;
        }
    }
}
